/**
 * 
 */
package com.jie.eclipse.pan.gef.dialog;

import org.eclipse.gef.tools.AbstractTool.Input;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.jie.eclipse.pan.bind.BaseDataBind;
import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.form.support.FormItem;
import com.jie.eclipse.pan.utils.StringBuilderEx;

/**
 * @author yanjie
 *
 */
public class GroupDialog  extends BaseDialog{
	/**
	 * @param parentShell
	 * @param data
	 */
	public GroupDialog(Shell parentShell, BaseDataEntity data,String action) {
		super(parentShell, data,action);
	}
	
	@Override
	protected Control createDialogArea(Composite paramComposite) {
		Color bgcolor = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
		Composite composite = new Composite(paramComposite, SWT.NONE);
		composite.setLayout(new GridLayout(4, false));
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		composite.setBackground(bgcolor);
		Label lb = null;
		GridData fh = new GridData(GridData.FILL_HORIZONTAL);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setLayoutData(fh);
		lb.setText("ID:");
		lb.setBackground(bgcolor);
		Text id = new Text(composite, SWT.BORDER);
		id.setLayoutData(new GridData(100, 15));
		this.getDataBind().bind("id", id);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setLayoutData(fh);
		lb.setText("原生态:");
		lb.setBackground(bgcolor);
		Button keep = new Button(composite, SWT.CHECK);
		keep.setLayoutData(new GridData(100, 15));
		keep.setData("true");
		this.getDataBind().bind("keep", keep);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setLayoutData(fh);
		lb.setText("列数:");
		lb.setBackground(bgcolor);
		Text colspan = new Text(composite, SWT.BORDER);
		colspan.setLayoutData(new GridData(100, 15));
		this.getDataBind().bind("colspan", colspan);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setText("列模型:");
		lb.setBackground(bgcolor);
		lb.setLayoutData(fh);
		Text colModel = new Text(composite, SWT.BORDER);
		colModel.setLayoutData(new GridData(100, 15));
		this.getDataBind().bind("colModel", colModel);
		
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setLayoutData(fh);
		lb.setText("标题:");
		lb.setBackground(bgcolor);
		Text caption = new Text(composite, SWT.BORDER);
		caption.setLayoutData(new GridData(100, 15));
		this.getDataBind().bind("caption", caption);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setLayoutData(fh);
		lb.setText("标题宽度:");
		lb.setBackground(bgcolor);
		Text captionWidth = new Text(composite, SWT.BORDER);
		captionWidth.setLayoutData(new GridData(100, 15));
		this.getDataBind().bind("captionWidth", captionWidth);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setLayoutData(fh);
		lb.setText("标题居左:");
		lb.setBackground(bgcolor);
		Button capPostion = new Button(composite, SWT.CHECK);
		capPostion.setLayoutData(new GridData(100, 15));
		capPostion.setData("left");
		this.getDataBind().bind("capPostion", capPostion);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setLayoutData(fh);
		lb.setText("隐藏标题:");
		lb.setBackground(bgcolor);
		Button captionDisplay = new Button(composite, SWT.CHECK);
		captionDisplay.setLayoutData(new GridData(100,15));
		captionDisplay.setData("false");
		this.getDataBind().bind("captionDisplay", captionDisplay);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setLayoutData(fh);
		lb.setText("隐藏分組:");
		lb.setBackground(bgcolor);
		Button hidden = new Button(composite, SWT.CHECK);
		hidden.setLayoutData(new GridData(100,15));
		hidden.setData("true");
		this.getDataBind().bind("hidden", hidden);
		
		this.reloadRecord();
		return paramComposite;
	}
	
	@Override
	public void initRootItem(BaseDataEntity data,BaseDataBind bind,StringBuilderEx code) {
		if(bind == null)return ;
		BaseDataEntity record = bind.getRecord();
		FormItem  group = getNewFormItem();
		group.configItem(record);
		this.setRoot(group);
	}
	
	@Override
	public void fillConfig(BaseDataEntity config, BaseDataBind dataBind) {
		if(config ==null || dataBind==null)return;
		BaseDataEntity record = dataBind.getRecord();
		config.spsnnv("id", record.gpsv("id"));
		config.spsnnv("colspan", record.gpsv("colspan"));
		config.spsnnv("colModel", record.gpsv("colModel"));
		config.spsnnv("caption", record.gpsv("caption"));
		config.spsnnv("captionWidth", record.gpsv("captionWidth"));
		config.spsnnv("capPostion", record.gpsv("capPostion"));
		config.spsnnv("captionDisplay", record.gpsv("captionDisplay"));
		config.spsnnv("keep", record.gpsv("keep"));
		config.spsnnv("hidden", record.gpsv("hidden"));
	}
	
	@Override
	public String getTitle() {
		return "分組框設置";
	}
}
